package cn.yeziji.netty.config.mq;

import cn.yeziji.forum.common.key.RabbitMQConfig;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 用户信息 MQ 配置
 *
 * <p>实现 BeanPostProcessor 类，使用 Bean 的生命周期函数。让生产者创建初始化队列
 *
 * @author gzkemays
 * @since 2022/11/08 10:28 PM
 */
@Configuration
public class UserMessageConfig {

  /** 用户消息队列 主要用于通知 */
  @Bean
  public Queue userMsgQueue() {
    return new Queue(RabbitMQConfig.USER_MSG, true, false, false);
  }

  /** 交换机 */
  @Bean
  public DirectExchange userMsgExchange() {
    return new DirectExchange(RabbitMQConfig.USER_MSG_EXCHANGE, true, false);
  }

  @Bean
  public Binding bindUserMsg() {
    return BindingBuilder.bind(userMsgQueue())
        .to(userMsgExchange())
        .with(RabbitMQConfig.USER_MSG_ROUTING_KEY);
  }
}
